<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=emulateIE7"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" type="text/css" href="css/style.css"/>
    <link rel="stylesheet" type="text/css" href="css/WdatePicker.css"/>
    <link rel="stylesheet" type="text/css" href="css/skin_/table.css"/>
    <link rel="stylesheet" type="text/css" href="css/jquery.grid.css"/>
    <link rel="stylesheet" type="text/css" href="../layui-v2.3.0/layui/css/layui.css"/>

    <title></title>
</head>

<body>
<div id="copySubject" style="display: none">
    <table class="layui-table">

        <input type="text" name="idtext" style="display: none"/>
        <tr>
            <td width="150">当前服务器文件地址：</td>
            <td><input style="border: 0px;outline:none;cursor: pointer;" class="layui-input"  type='text' name="src" /></td>
        </tr>
        <tr>
            <td>请输入文件归档地址：</td>
            <td><input style="border: 0px;outline:none;cursor: pointer;" class="layui-input"  type='text' name="des" /></td>
        </tr>

    </table>
    <div style="text-align: center">
        <input type="button" class="layui-btn layui-btn-primary" value="确认" onclick="submit()"/>
    </div>
</div>
<div id = "container">
<div id="hd"></div>
<div id="bd">
    <div id="main">
        <div class="search-box ue-clear">
            <fieldset class="layui-elem-field layui-field-title">
                <legend>论文列表</legend>
                <br>

            </fieldset>

            <div class="subjectTable" id="subject">
                <table id="subjecttable" class="layui-table">
                    <colgroup>
                        <col width="50">
                        <col width="150">
                        <col width="150">
                        <col width="150">
                        <col width="200">
                        <col width="150">
                        <col width="150">
                        <col>
                    </colgroup>
                    <thead>
                    <tr>
                        <th>id</th>
                        <th>课程名称</th>
                        <th>指导老师</th>
                        <th>发起人</th>
                        <th>上传时间</th>
                        <th>状态</th>
                        <th>附件</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="subjectGrid" class="tbody">
                    <tr v-for="pre in preview" onclick="click(this)">
                        <td id="addr" style="display:none;">{{ pre.subjectadd }}</td>
                        <td id="id">{{ pre.uuid }}</td>
                        <td>{{ pre.subname }}</td>
                        <td>{{ pre.subauth }}</td>
                        <td>{{ pre.creater}}</td>
                        <td>{{ pre.subcreatetime }}</td>
                        <td>{{ pre.status }}</td>
                        <td><a onclick="downSubject(this)">查看附件</a> </td>
                        <td><a onclick="copySubject(this)">归档</a></td>
                    </tr>
                    </tbody>
                </table>
                <div id="pTable2" style="width: 1200px;">
                    <div id="laypage">
                    </div>
                </div>
            </div>

            </div>
        </div>
    </div>
</div>
</div>
</div>
</div>

</body>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/global.js"></script>
<script type="text/javascript" src="js/jquery.select.js"></script>
<script type="text/javascript" src="js/core.js"></script>
<script type="text/javascript" src="js/jquery.pagination.js"></script>
<script type="text/javascript" src="js/jquery.grid.js"></script>
<script type="text/javascript" src="js/WdatePicker.js"></script>
<script type="text/javascript" src="../js/jquery.cookie.js"></script>
<script type="text/javascript" src="../js/application.js"></script>
<script type="text/javascript" src="../js/vue.js"></script>
<script type="text/javascript" src="../layui-v2.3.0/layui/layui.js"></script>
<script type="text/javascript">



    var subject = new Vue({
        el: '#subject',
        data: {
            preview: ""
        }
    });
    layui.use('laypage', function () {
        var laypage = layui.laypage;
        var jon = {};
        jon['token'] = getCookie('token');
        $.ajax({
            url:"/getSubjectFileCount",
            type:"POST",
            data:{},
            success:function (res) {
                debugger;
                console.log(res);
                laypage.render({
                    elem: 'pTable2'
                    , count: res
                    , limit: 5
                    , jump: function (obj, first) {
                        //obj包含了当前分页的所有参数，比如：
                        //console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
                        //  console.log(obj.limit); //得到每页显示的条数
                        debugger;
                        var jon={};
                        jon['curr']=obj.curr;
                        jon['limit']=obj.limit;
                        $.ajax({
                            url: "/getSubjectFile",
                            type: "POST",
                            data: {"jon": JSON.stringify(jon)},
                            success: function (res) {
                                debugger;
                                var a = res.replace(/"status":"0"/g, "\"status\":\"未审核\"");
                                var b = a.replace(/"status":"1"/g, "\"status\":\"审核中\"");
                                var c = b.replace(/"status":"2"/g, "\"status\":\"已审核\"");
                                subject.preview = JSON.parse(c);
                            }
                        });
                        //首次不执行
                        if (1) {
                            //do something
                        }
                    }
                });
            },
            error:function (res) {
                layui.use('layer', function () {
                    var layer = layui.layer;
                    layer.msg('获取数据失败，请重试!!!', {
                        icon: 2
                    });
                });
            }
        });
    });


    function downSubject(e) {
        debugger;
        var row = e.parentNode.parentNode.rowIndex;
        var name = $("#subjectGrid tr:eq(" + (row - 1) + ") td:eq(3)").html();
        var addr = $("#subjectGrid tr:eq(" + (row - 1) + ") td:eq(0)").html();
        //===============================
        var form=$("<form>");
        form.attr("style","display:none");
        form.attr("class","downSubjectForm");
        form.attr("target","");
        form.attr("method","post");//提交方式为post
        form.attr("action","/downloadSubject");//定义action
        //=================================
        var input = $("<input>");
        input.attr("name","addr");
        input.attr("id","addrtext");
        input.attr("type","text");
        input.attr("value",addr);
        $("body").append(form);
        $(".downSubjectForm").append(input);
        debugger;
        form.submit();
    }
    
    function copySubject(e) {
        var row = e.parentNode.parentNode.rowIndex;
        var srcPathStr = $("#subjectGrid tr:eq(" + (row - 1) + ") td:eq(0)").html();
        $('input[name="src"]').val(srcPathStr);
        layui.use('layer', function () {
            var layer = layui.layer;
            layer.open({
                type: 1,
                title: '论文归档',
                closeBtn: 2,
                area: ['800px', '320px'],
                anim: 1,
                shadeClose: true,
                content: $('#copySubject')
            });
        });
    }

    function submit() {
        layer.confirm('归档为不可逆操作，是否确认文件归档？', {
            btn: ['确认','取消'] //按钮
        }, function(){
            var jon = {};
            jon['des'] = $('input[name="des"]').val();
            jon['src'] = $('input[name="src"]').val();
            $.ajax({
                url: "/copyReport",
                type: "POST",
                data: {"jon": JSON.stringify(jon)},
                success: function (res) {
                    debugger;
                    layui.use('layer', function () {
                        var layer = layui.layer;
                        layer.msg('文件已归档!!!', {
                            icon: 1
                        });
                    });
                    setTimeout("location.reload()",2000);
                },error:function () {
                    layui.use('layer', function () {
                        var layer = layui.layer;
                        layer.msg('io流异常，请重试!!!', {
                            icon: 2
                        });
                    });
                }
            });
        }, function(){

        });
    }


</script>
</html>
